home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / basic / ubmalm.zip / chinese.ub < prev    next >
Text File  |  1990-08-22  |  690b  |  18 lines

  1.  1170   *Chinese(N%,&A(),&B(),&M(),&Soln,&Modulus)
  2.  1180   ' Chinese remaindering algorithm, modeled on the Pascal version.
  3.  1190   ' 21 August 1990
  4.  1200   local C,Ca,Te,Ta,I%,Aa,Bb
  5.  1210   if N%<=0 then Modulus=0:return endif
  6.  1220   gosub *Fcgcd(A(1),M(1),&C,&Ca)
  7.  1230   Te=B(1)\C:if res then Modulus=0:return endif
  8.  1240   Soln=Te*Ca:Modulus=M(1)\C
  9.  1250   for I%=2 to N%
  10.  1260   Aa=A(I%)*Modulus:Bb=B(I%)-A(I%)*Soln
  11.  1270   gosub *Fcgcd(Aa,M(I%),&C,&Ca)
  12.  1280   Te=Bb\C:if res then Modulus=0:cancel for:return endif
  13.  1290   Soln=Soln+Modulus*Te*Ca
  14.  1300   Modulus=Modulus*(M(I%)\C)
  15.  1310   Soln=Soln@Modulus
  16.  1320   next I%
  17.  1330   return ' End of subroutine Chinese
  18.